package com.tzstcl.sys.monitor.ctrl;

import com.github.pagehelper.PageInfo;
import com.tzstcl.base.ctrl.BaseCtrl;
import com.tzstcl.base.model.AjaxResult;
import com.tzstcl.sys.monitor.model.SysOperLog;
import com.tzstcl.sys.monitor.service.impl.SysOperLogServiceImpl;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * 公司：天筑科技股份有限公司
 * 作者：zhugq
 * 日期：2018年09月21日
 * 说明：操作日志Controller
 */
@Controller
@RequestMapping("/admin/sysOperLog")
public class SysOperLogCtrl extends BaseCtrl {

    @Autowired
    private SysOperLogServiceImpl sysOperLogServiceImpl;

    /**
     * 新增 修改
     *
     * @param sysOperLog
     * @return
     */
    @RequestMapping("/save")
    @RequiresPermissions(value = {"sysOperLog:edite", "sysOperLog:add"}, logical = Logical.OR)
    @ResponseBody
    public AjaxResult save(@Valid SysOperLog sysOperLog) {
        return toAjax(sysOperLogServiceImpl.insertOrUpdate(sysOperLog));
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sysOperLog:delete")
    @ResponseBody
    public AjaxResult delete(String ids) {
        return toAjax(sysOperLogServiceImpl.deleteBatchIds(ids));
    }

    /**
     * 获取单条信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/get")
    @RequiresPermissions("sysOperLog:view")
    @ResponseBody
    public AjaxResult get(Long id) {
        return success("获取信息成功", sysOperLogServiceImpl.getOne(id));
    }

    /**
     * 获取查询的分页数据
     *
     * @param sysOperLog
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions("sysOperLog:view")
    @ResponseBody
    public PageInfo<SysOperLog> list(SysOperLog sysOperLog) {
        return sysOperLogServiceImpl.selectPage(sysOperLog);
    }

    /**
     * list页面导航
     *
     * @return
     */
    @RequiresPermissions("sysOperLog:view")
    @RequestMapping("/toList")
    public String toList() {
        return "admin/sys/monitor/sysOperLogList";
    }

    /**
     * form页面导航
     *
     * @return
     */
    @RequiresPermissions(value = {"sysOperLog:edite", "sysOperLog:add"}, logical = Logical.OR)
    @RequestMapping("/toForm")
    public String toForm() {
        return "admin/sys/monitor/sysOperLogForm";
    }
}